package hzau.utils;

import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import jodd.io.FileUtil;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;

public class CodeUtil {
        public static String QrGenerate(String url) throws Exception {
            QrConfig config=new QrConfig(800,800);
            config.setErrorCorrection(ErrorCorrectionLevel.L);
            config.setImg("C:\\Users\\user\\Desktop\\简历\\证件照\\myImage.jpg");
            File generate = QrCodeUtil.generate(url, config, FileUtil.file("d:/qrcode.jpg"));
            //读取文件
            FileInputStream in_file = new FileInputStream(generate);

            //转MultipartFile
            MultipartFile multi = new MockMultipartFile( generate.getName(),in_file);

            return OssUtils.upload(multi);
        }
}
